#include "../include/make/xml_make.h"
#include "../include/common/hstring.hpp"
#include "../include/common/tools.hpp"

int main(int argc, char** argv) {

    bool l_result = false;
    do {
        if (argc < 4) {
            break;
        }

        make::xml_make_t l_make_t;
        ydd::wstring l_src_path(ydd::wstring::locale_to_unicode(argv[2]));
        if (!l_make_t.initialize(l_src_path)) {
            break;
        }
        if (!l_make_t.load()) {
            break;
        }
        ydd::wstring l_src_name(common::tools::get_file_name(l_src_path, false));
        ydd::wstring l_dst_dir(ydd::wstring::locale_to_unicode(argv[3]));

        common::tools::add_slash(l_dst_dir);
        l_dst_dir << l_src_name;
        ydd::wstring l_type(ydd::wstring::locale_to_unicode(argv[1]));
        if (l_type.is_equal("-java", false)) {
            l_result = l_make_t.save_java(l_dst_dir << ".java");
        } else if (l_type.is_equal("-cxx", false)) {
            l_result = l_make_t.save_cxx(l_dst_dir << ".hpp");
        } else if (l_type.is_equal("-js", false)) {
            l_result = l_make_t.save_js(l_dst_dir << ".js");
        }
    } while (0);

    if (!l_result) {
        printf(ydd::wstring(L"usage: -java/-cxx/-js src_path dst_path\n").to_locale_str().c_str());
        return -1;
    }
    return l_result ? 0 : -1;
}